package com.neusoft.tijian.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.neusoft.tijian.entity.Users;
import com.neusoft.tijian.mapper.UsersMapper;
import com.neusoft.tijian.service.UserService;
import com.neusoft.tijian.vo.RespVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UsersMapper usersMapper;

    @Override
    public RespVo userLogin(Users users) {
        LambdaQueryWrapper<Users> queryWrapper = new LambdaQueryWrapper<Users>()
                .eq(Users::getUserId, users.getUserId());
        List<Users> userList = usersMapper.selectList(queryWrapper);
        if (userList.size() > 0){
            if (!users.getPassword().equals(userList.get(0).getPassword())){
                return RespVo.error("密码错误");
            }
            return RespVo.success(userList.get(0));
        }
        return RespVo.error("用户不存在");
    }

    @Override
    public RespVo register(Users users) {
        usersMapper.insert(users);
        return RespVo.success();
    }
}
